<template>
  <el-dialog title="分配权限" :visible.sync="rightDialogVisible" width="30%">
    <el-tree
      :data="rightList"
      show-checkbox
      node-key="id"
      :default-expanded-keys="rightIds"
      :default-checked-keys="rightIds"
      :props="defaultProps"
      ref="tree"
    >
    </el-tree>
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" @click="editRight">确 定</el-button>
      <el-button @click="rightDialogVisible = false">取 消</el-button>
    </span>
  </el-dialog>
</template>

<script>
export default {
  props: {
    rightDialogVisible: {
      type: Boolean,
      default: () => {
        return false;
      }
    },
    rightList: Array,
    rightIds: Array
  },
  data() {
    return {
      defaultProps: {
        children: "children",
        label: "name"
      },
      allCheckedKeys: []
    };
  },
  methods: {
    editRight() {
      const checkedKeys = this.$refs.tree.getCheckedKeys();
      const HalfCheckedKeys = this.$refs.tree.getHalfCheckedKeys();
      this.allCheckedKeys = [...checkedKeys, ...HalfCheckedKeys];
      this.$emit('editRight', this.allCheckedKeys)
    }
  }
};
</script>

<style scoped></style>
